<?php

namespace Modules\System\Http\Controllers;

/*
 * 集合类
 */
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Chinadmin\Models\AccountModel;
use Modules\Chinadmin\Models\UserModel;
use Modules\System\Services\Sys\C;
use Modules\System\Services\Sys\Database;

class Universal extends Controller
{

    public function __construct(Request $request = null){

        $i = $request->input();
        foreach($i as $k=>$v){
            if((gettype($v) == 'string') || (gettype($v) == 'NULL')){
                if($v == "''" || $v == "" || $v == null){
                    unset($i[$k]);
                }
            }
        }
        if(!isset(C::$m[$i['m']])){
            $i['model'] = 'Modules\Chinadmin\Models\\'.ucfirst($i['m']).'Model';
        }else{
            $i['model'] = C::$m[$i['m']];
        }

        //连接参数做相关转换
        $i = Database::transformation($i);

        $this->user = UserModel::getUserInfoByToken($i['token']);
        $this->i = $i;

    }

    /**
     * showdoc
     * @catalog 公共
     * @title 集合添加
     * @description 集合添加
     * @method post
     *
     * @param token 必选 string  token
     *
     * @return mixed
     */
    public function insert(Request $request){
        $re = Database::insert($this->i,$this->user);
        mds_if_response($re);
    }

    /**
     * showdoc
     * @catalog 公共
     * @title 集合删除
     * @description 集合删除
     * @method post
     *
     * @param token 必选 string token
     *
     * @return mixed
     */
    public function delete(Request $request){
        $re = Database::delete($this->i,$this->user);
        mds_if_response($re);
    }

    /**
     * showdoc
     * @catalog 公共
     * @title 集合更新
     * @description 集合更新
     * @method post
     *
     * @param token 必选 string  token
     *
     * @return mixed
     */
    public function update(Request $request){
        $re = Database::update($this->i,$this->user);
        mds_if_response($re);
    }

    /**
     * showdoc
     * @catalog 公共
     * @title 集合搜索
     * @description 集合搜索
     * @method post
     *
     * @param token 必选 string token
     * @param page 必选 int 分页:1
     * @param pazeSize 必选 int 页数:10
     * @param search 必选 string [{"field":"dynamic_id","condition":"eq","val":"11"}]
     *
     * @return mixed
     */
    public function search(Request $request){
        $list = Database::search($this->i,$this->user);
        mdsResponse(200,"获取成功",$list);
    }

}
